/*
 * @Author: admin@attacker.club
 * @Date: 2022-11-09 13:48:44
 * @LastEditTime: 2022-11-09 14:30:42
 * @Description:
 */

// 手机号验证
export function phone(rule, value, callback) {
  var regex = /^1\d{10}$/;
  // 实现非必填; 1.不使用required之外,2.让空或者undefined通过
  if (value == "" || value == undefined || value == null) {
    callback();
  } else {
    if (
      regex.test(value || value == "" || value == undefined || value == null)
    ) {
      callback();
    } else {
      callback(new Error("请输入正确的手机号"));
    }
  }
}

// 邮箱验证
export function email(rule, value, callback) {
  var regex = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
  if (value == "" || value == undefined || value == null) {
    callback();
  } else {
    if (!regex.test(value) && value != "") {
      callback(new Error("请输入正确邮箱"));
    } else {
      callback();
    }
  }
}
